/**
  * Copyright 2019 bejson.com 
  */
package com.xingkeduo.dto.transter.paydetail;

import com.xingkeduo.dto.MarketActivityDto;
import com.xingkeduo.dto.OrderDetailResponseDto;
import com.xingkeduo.pojo.enums.OrderSource;
import com.xingkeduo.utils.DateTimeUtils;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

@Data
public class ContentPayDetail {

    private StorePayDetail store;
    private String pay_price;
    private String coupon_price;
    private String total_price;
    private String discount_price;
    private String reduce_price;
    private Coupon coupon;
    private Card card;
    private String suggest_coupon_id;
    private long suggest_card_id;
    private double money;
    private String appointment_date;
    private String appointment_time;
    private String store_id;
    private String service_type;
    private String selected_ticket_type;
    private String admin_id;
    private String choose_admin;
    private String admin_avatar;
    private String admin_name;
    private long expiration_time;
    private long delta_time;
    private int no_cert_card_detail_id;
    private Boolean has_activity;
    private Boolean is_most_coupon;
    private String activity_name;
    private String appointment_date_show;
    private String server_name;
    private String all_price;

    private Activity activity;
    private String suggest_activity_id;
    private Boolean has_discount;


    public void covert(OrderDetailResponseDto data, StorePayDetail storePayDetail, Coupon coupon, Card card,String activityName,Activity activity, MarketActivityDto marketActivityInfo) {
        this.has_discount=true;
        LocalDateTime time = data.getCreatedTime().plusSeconds(60);
        this.store = storePayDetail;
        this.pay_price=String.valueOf(data.getPayPrice());
        this.coupon_price=String.valueOf(data.getMarketingPrice());
        this.total_price=String.valueOf(data.getAllPrice());
            this.discount_price = String.valueOf(data.getCouponPrice());
            this.reduce_price=String.valueOf(data.getActivityPrice());
        this.coupon=coupon;
        this.card=card;

        this.money = 141.04;
        this.appointment_date= DateTimeUtils.yyyy_MM_dd(data.getAppointmentStartTime());
        this.appointment_time=DateTimeUtils.HH_mm(data.getAppointmentStartTime());
        this.store_id=String.valueOf(data.getStoreId());
        this.service_type=String.valueOf(data.getServiceTypeId());
        this.selected_ticket_type="3";
        if(OrderSource.BRANCH.equals(data.getOrderSource()) || OrderSource.ALIPAY_SCAN.equals(data.getOrderSource())){
            this.selected_ticket_type="1";
        }

//        this.admin_id=data.getAdminId();
//        this.admin_avatar = data.getAdminAvatar();
//        this.admin_name = data.getAdminNickName();

        this.admin_id=data.getAppointmentAdminId();
        this.admin_avatar = data.getAppointmentAdminAvatar();
        this.admin_name = data.getAppointmentAdminNickName();

        this.expiration_time=time.toEpochSecond(ZoneOffset.of("+8"));
        this.delta_time= Duration.between(time, LocalDateTime.now()).getSeconds()>=0?0:Math.abs(Duration.between(time, LocalDateTime.now()).getSeconds());

//        this.has_activity= StringUtils.isNotEmpty(data.getActivityType())?true:false;
        this.has_activity= true;

        this.is_most_coupon="1".equals(data.getOptimal())?true:false;
        this.activity_name=activityName;
        this.appointment_date_show=DateTimeUtils.yyyyMMdd(data.getAppointmentStartTime());;
        this.server_name=data.getServiceTypeName();
        this.choose_admin="0";
        this.all_price=String.valueOf(data.getAllPrice());
        this.activity = activity;
        this.suggest_activity_id="0";
        this.suggest_coupon_id="0";
        this.suggest_card_id=0;
        if (marketActivityInfo!=null && marketActivityInfo.getActivityType() != null) {
            this.suggest_activity_id=String.valueOf(marketActivityInfo.getActivityId());
        }

        if (marketActivityInfo !=null && marketActivityInfo.getMarketingType() != null) {
            if(marketActivityInfo.getMarketingType()==1){
                this.suggest_coupon_id=String.valueOf(marketActivityInfo.getMarketingId());
            }
            if(marketActivityInfo.getMarketingType()==2){
                this.suggest_card_id=marketActivityInfo.getMarketingId();
            }
        }



    }

}